require_relative 'CPFService'
require_relative 'StringUtils'

class UpdateService < CPFService
	include StringUtils
	UPDATE_REQUEST = '<SOAP:Envelope xmlns:SOAP="http://schemas.xmlsoap.org/soap/envelope/"><SOAP:Header><WSSecurity/></SOAP:Header><SOAP:Body><UpdateScripts xmlns="http://schemas.cordys.com/bsf/uc/webapps/1.0/{tenant}/ScriptUpload"><tns:parameters xmlns:tns="http://schemas.cordys.com/bsf/uc/webapps/1.0/{tenant}/ScriptUpload"><tns:tuple><tns:old><tns:Scripts><tns:ScriptID>{scriptId}</tns:ScriptID></tns:Scripts></tns:old><tns:new><tns:Scripts><tns:ScriptID>{scriptId}</tns:ScriptID><tns:URL>{URL}</tns:URL></tns:Scripts></tns:new></tns:tuple></tns:parameters></UpdateScripts></SOAP:Body></SOAP:Envelope>'

	def initialize assertion
		super assertion
	end

	def update id, url
		requestMap = {}
		requestMap[/\{tenant\}/] = @@properties["tenant"]
		requestMap[/\{scriptId\}/] = id
		requestMap[/\{URL\}/] = url
		@request = replaceMap UPDATE_REQUEST, requestMap
		fireService
	end
end